如何在Ubuntu20.04上使用Seafile同步和共享文件

您所在的位置:网站首页 seafile ubuntu20 如何在Ubuntu20.04上使用Seafile同步和共享文件

如何在Ubuntu20.04上使用Seafile同步和共享文件

2024-04-19 06:16| 来源: 网络整理| 查看: 265

目录 1 介绍 2 先决条件 3 第 1 步 — 为 Seafile 组件创建数据库 4 第 2 步 — 安装依赖项并下载 Seafile 5 第 3 步 — 配置 Seafile 服务器 6 第 4 步 — 配置 Apache Web 服务器 7 第 5 步 — 更新 Seafile 的配置并启动服务 8 第 6 步 — 使 Seafile 服务器在系统引导时启动 9 第 7 步 — 测试文件同步和共享功能 10 结论 介绍

Seafile是一个开源、自托管、文件同步和共享平台。 用户可以在自己的服务器上存储和选择性地加密数据,存储空间是唯一的限制。 使用 Seafile,您可以使用跨平台同步和受密码保护的指向具有过期日期的文件的链接来共享文件和文件夹。 文件版本控制功能意味着用户可以恢复已删除和修改的文件或文件夹。

在本教程中,您将在 Ubuntu 20.04 服务器上安装和配置 Seafile。 您将使用 MariaDB 存储 Seafile 的不同组件的数据,并使用 Apache 作为代理服务器来处理 Web 流量。 完成本教程后,您将能够使用 Web 界面从桌面或移动客户端访问 Seafile,允许您与服务器上的其他用户或组或与公众同步和共享您的文件。

先决条件

在开始本指南之前,您需要以下内容:

按照此 Initial Server Setup for Ubuntu 20.04 教程设置一台具有至少 2GB RAM 的 Ubuntu 20.04 服务器,包括 sudo 非 root 用户和防火墙。 安装并配置了 MariaDB 数据库服务器。 按照 如何在 Ubuntu 20.04 上安装 MariaDB 教程中的步骤进行操作。 按照 How To Install the Apache Web Server on Ubuntu 20.04 为注册域配置虚拟主机的 Apache Web 服务器。 按照 How To Secure Apache with Let's Encrypt on Ubuntu 20.04 教程安装在您的服务器上的 SSL 证书。 完全注册的域名。 本教程将自始至终使用 your_domain。 为您的服务器设置了以下两个 DNS 记录。 您可以按照此 DigitalOcean DNS 介绍了解如何添加它们的详细信息。 带有 your_domain 的 A 记录指向您服务器的公共 IP 地址。 带有 www.your_domain 的 A 记录指向您服务器的公共 IP 地址。

第 1 步 — 为 Seafile 组件创建数据库

Seafile 需要三个组件才能正常工作。 这三个组成部分是:

Seahub:Seafile 的 Web 前端,使用 Django Web 框架用 Python 编写。 通过 Seahub,您可以使用 Web 浏览器访问、管理和共享您的文件。 Seafile server:管理原始文件上传、下载和同步的数据服务守护进程。 您不直接与服务器交互,而是使用客户端程序之一或 Seahub Web 界面。 Ccnet server:RPC 服务守护进程,用于启用 Seafile 不同组件之间的内部通信。 例如,当您使用 Seahub 时,它能够使用 Ccnet RPC 服务从 Seafile 服务器访问数据。

这些组件中的每一个都将其数据分别存储在自己的数据库中。 在此步骤中,您将在继续设置服务器之前创建三个 MariaDB 数据库和一个用户。

首先,使用您的用户名和 IP 地址使用 SSH 登录服务器:

ssh sammy@your_server_ip

以管理员身份(root)连接到 MariaDB 数据库服务器:

sudo mariadb

在 MariaDB 提示符下,使用以下 SQL 命令创建数据库用户:

CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';

接下来,您将创建以下数据库来存储三个 Seafile 组件的数据:

Ccnet 服务器的 ccnetdb。 seahubdb 用于 Seahub Web 前端。 Seafile 文件服务器的 seafiledb。

在 MariaDB 提示符下,创建您的数据库:

CREATE DATABASE `ccnetdb` CHARACTER SET = 'utf8'; CREATE DATABASE `seafiledb` CHARACTER SET = 'utf8'; CREATE DATABASE `seahubdb` CHARACTER SET = 'utf8';

然后,授予 Seafile 数据库用户访问和更改这些数据库的所有权限:

GRANT ALL PRIVILEGES ON `ccnetdb`.* to `sammy`@localhost; GRANT ALL PRIVILEGES ON `seafiledb`.* to `sammy`@localhost; GRANT ALL PRIVILEGES ON `seahubdb`.* to `sammy`@localhost;

输入 exit 退出 MariaDB 提示符:

exit

现在您已经创建了一个用户和存储每个 Seafile 组件数据所需的数据库,您将安装配置 Seafile 服务器包所需的依赖项。

第 2 步 — 安装依赖项并下载 Seafile

Seafile 的某些部分是用 Python 编写的,因此需要额外的 Python 模块和程序才能工作。 在这一步中,您将在下载和解压 Seafile 服务器包之前安装这些必需的依赖项。

首先,安装 pip — Python 包管理器。 相应的 Debian 软件包称为 python3-pip。 您可以使用 apt 安装它:

sudo apt install -y python3-pip

安装 pip 后,您可以使用 pip3 命令从 Python 包索引 (PyPI) 安装其他依赖项:

pip3 install Pillow captcha django-simple-captcha

注意: 不需要将 sudo 与上述 pip3 install 命令一起使用。 这些软件包将安装在 /home/sammy/.local/lib/python3.8/site-packages 下的 sammy 用户主目录中,因此不需要 root 权限。

Seafile 需要 Pillow,一个用于图像处理的 python 库,以及 captcha 和 django-simple-captcha 来提供验证码支持。

现在您已经安装了必要的依赖项,您可以下载 Seafile 服务器包。

Seafile 在安装过程中会创建额外的目录。 为了使它们井井有条,请创建一个新目录并更改为该目录:

mkdir seafile cd seafile

您现在可以通过运行以下命令从 网站 下载 Seafile 服务器的最新版本(撰写本文时为 7.1.4):

wget https://download.seadrive.org/seafile-server_7.1.4_x86-64.tar.gz

Seafile 以压缩 tar 存档的形式分发下载,这意味着您需要在继续之前将其解压缩。 使用 tar 提取存档:

tar -zxvf seafile-server_7.1.4_x86-64.tar.gz

现在切换到提取的目录:

cd seafile-server-7.1.4

在这个阶段,您已经下载并解压了 Seafile 服务器包,并且还安装了必要的依赖项。 您现在已准备好配置 Seafile 服务器。

第 3 步 — 配置 Seafile 服务器

在您首次启动服务之前,Seafile 需要一些有关您的设置的信息。 这包括域名和数据库配置等详细信息。 要启动一系列问题提示以提供此信息,您可以运行脚本 setup_seafile_mysql.sh,该脚本包含在您在上一步中提取的存档中。

使用 bash 运行脚本:

bash setup-seafile-mysql.sh

按 ENTER 继续。

该脚本现在将提示您一系列问题。 无论何时提及默认值,按 ENTER 键将使用该值。

本教程使用 Seafile 作为服务器名称,但您可以根据需要更改它。

What is the name of the server? It will be displayed on the client. 3 - 15 letters or digits [ server name ] Seafile

接下来,输入此 Seafile 实例的域名。

What is the ip or domain of the server?. For example: www.mycompany.com, 192.168.1.101 [ This server's ip or domain ] your_domain

对于文件服务器端口,按 ENTER 接受默认值。

Which port do you want to use for the seafile fileserver? [ default "8082" ]

下一个提示允许您确认数据库配置。 您可以创建新数据库或使用现有数据库进行设置。 对于本教程,您已在步骤 1 中创建了必要的数据库,因此在此处选择选项 2。

------------------------------------------------------- Please choose a way to initialize seafile databases: ------------------------------------------------------- [1] Create new ccnet/seafile/seahub databases [2] Use existing ccnet/seafile/seahub databases [ 1 or 2 ] 2

剩下的问题与 MariaDB 数据库服务器有关。 您只需提供您在步骤 1 中创建的 mariadb 用户的用户名和密码。 按 ENTER 接受 host 和 port 的默认值。

What is the host of mysql server? [ default "localhost" ] What is the port of mysql server? [ default "3306" ] Which mysql user to use for seafile? [ mysql user for seafile ] sammy What is the password for mysql user "seafile"? [ password for seafile ] password

提供密码后,脚本将请求 Seafile 数据库的名称。 本教程使用 ccnetdb、seafiledb 和 seahubdb。 然后,该脚本将验证是否成功连接到数据库,然后再继续显示初始配置的摘要。

Enter the existing database name for ccnet: [ ccnet database ] ccnetdb verifying user "sammy" access to database ccnetdb ... done Enter the existing database name for seafile: [ seafile database ] seafiledb verifying user "sammy" access to database seafiledb ... done Enter the existing database name for seahub: [ seahub database ] seahubdb verifying user "sammy" access to database seahubdb ... done --------------------------------- This is your configuration --------------------------------- server name: Seafile server ip/domain: your_domain seafile data dir: /home/sammy/seafile/seafile-data fileserver port: 8082 database: use existing ccnet database: ccnetdb seafile database: seafiledb seahub database: seahubdb database user: sammy -------------------------------- Press ENTER to continue, or Ctrl-C to abort ---------------------------------

按 ENTER 确认。

OutputGenerating ccnet configuration ... done Successly create configuration dir /home/sammy/seafile/ccnet. Generating seafile configuration ... done Generating seahub configuration ... ---------------------------------------- Now creating seahub database tables ... ---------------------------------------- creating seafile-server-latest symbolic link ... done ----------------------------------------------------------------- Your seafile server configuration has been finished successfully. ----------------------------------------------------------------- run seafile server: ./seafile.sh { start | stop | restart } run seahub server: ./seahub.sh { start | stop | restart } ----------------------------------------------------------------- If you are behind a firewall, remember to allow input/output of these tcp ports: ----------------------------------------------------------------- port of seafile fileserver: 8082 port of seahub: 8000 When problems occur, Refer to https://github.com/haiwen/seafile/wiki for information.

由于您将在 Apache 后面运行 Seafile,因此不需要在防火墙中打开端口 8082 和 8000,因此您可以忽略这部分输出。

您已完成服务器的初始配置。 在下一步中,您将在启动 Seafile 服务之前配置 Apache Web 服务器。

第 4 步 — 配置 Apache Web 服务器

在这一步中,您将配置 Apache Web 服务器以将所有请求转发到 Seafile。 以这种方式使用 Apache 允许您使用没有端口号的 URL,启用到 Seafile 的 HTTPS 连接,并利用 Apache 提供的缓存功能以获得更好的性能。

要开始转发请求,您需要在 Apache 配置中启用 proxy_http 模块。 该模块提供代理 HTTP 和 HTTPS 请求的功能。 以下命令将启用该模块:

sudo a2enmod proxy_http

注意: 此设置还需要 Apache rewritessl 模块。 您已经在先决条件部分列出的第二个 Apache 教程中启用了这些模块,作为配置 Let's Encrypt 的一部分。

接下来,更新 your_domain 的虚拟主机配置,将请求转发到 Seafile 文件服务器和 Seahub Web 界面。

在文本编辑器中打开配置文件:

sudo nano /etc/apache2/sites-enabled/your_domain-le-ssl.conf

从 ServerAdmin 到 SSLCertificateKeyFile 的行是作为先决条件的一部分设置的初始 Apache 和 Let's Encrypt 配置的一部分。 添加突出显示的内容,从 Alias 开始并以 ProxyPassReverse 指令结束:

/etc/apache2/sites-enabled/your_domain-le-ssl.conf

ServerAdmin admin@your_domain ServerName your_domain ServerAlias www.your_domain DocumentRoot /var/www/your_domain/html ErrorLog ${APACHE_LOG_DIR}/your_domain-error.log CustomLog ${APACHE_LOG_DIR}/your_domain-access.log combined SSLCertificateFile /etc/letsencrypt/live/your_domain/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/your_domain/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf Alias /media /home/sammy/seafile/seafile-server-latest/seahub/media Require all granted # seafile fileserver ProxyPass /seafhttp http://127.0.0.1:8082 ProxyPassReverse /seafhttp http://127.0.0.1:8082 RewriteEngine On RewriteRule ^/seafhttp - [QSA,L] # seahub web interface SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 ProxyPass / http://127.0.0.1:8000/ ProxyPassReverse / http://127.0.0.1:8000/

Alias 指令将 URL 路径 your_domain/media 映射到 Seafile 使用的文件系统中的本地路径。 以下 Location 指令允许访问此目录中的内容。 ProxyPass 和 ProxyPassReverse 指令使 Apache 充当此主机的反向代理,将请求转发到 / 和 /seafhttp 到 Seafile Web 界面和文件服务器分别在本地主机端口 8000 和 8082 上运行。 RewriteRule 指令将所有请求原封不动地传递给 /seafhttp 并停止处理进一步的规则 ([QSA,L])。

保存并退出文件。

测试虚拟主机配置是否有语法错误:

sudo apache2ctl configtest

如果它报告 Syntax OK,那么您的配置没有问题。 重新启动 Apache 以使更改生效:

sudo systemctl restart apache2

您现在已将 Apache 配置为充当 Seafile 文件服务器和 Seahub 的反向代理。 接下来,您将在启动服务之前更新 Seafile 配置中的 URL。

第 5 步 — 更新 Seafile 的配置并启动服务

由于您现在使用 Apache 代理对 Seafile 的所有请求,因此您需要在启动 Seafile 服务之前使用文本编辑器更新 conf 目录中 Seafile 配置文件中的 URL。

在文本编辑器中打开 ccnet.conf:

nano /home/sammy/seafile/conf/ccnet.conf

修改文件中的 SERVICE_URL 设置,使其指向新的 HTTPS URL,不带端口号,例如:

更新 /home/sammy/seafile/conf/ccnet.conf

SERVICE_URL = https://your_domain

添加内容后保存并退出文件。

现在在文本编辑器中打开 seahub_settings.py:

nano /home/sammy/seafile/conf/seahub_settings.py

您现在可以在文件中添加 FILE_SERVER_ROOT 设置,以指定文件服务器侦听文件上传和下载的路径:

更新 /home/sammy/seafile/conf/seahub_settings.py

SECRET_KEY = "..." FILE_SERVER_ROOT = 'https://your_domain/seafhttp'

保存并退出seahub_settings.py。

现在您可以启动 Seafile 服务和 Seahub 界面:

cd /home/sammy/seafile/seafile-server-7.1.4 ./seafile.sh start ./seahub.sh start

由于这是您第一次启动 Seahub 服务,它会提示您创建一个管理员帐户。 输入此管理员用户的有效电子邮件地址和密码:

OutputWhat is the email for the admin account? [ admin email ] admin@your_domain What is the password for the admin account? [ admin password ] password-here Enter the password again: [ admin password again ] password-here ---------------------------------------- Successfully created seafile admin ---------------------------------------- Seahub is started Done.

在网络浏览器中打开 https://your_domain 并使用您的 Seafile 管理员电子邮件地址和密码登录。

成功登录后,您可以访问管理界面或创建新用户。

现在您已验证 Web 界面工作正常,您可以在下一步中启用这些服务在系统启动时自动启动。

第 6 步 — 使 Seafile 服务器在系统引导时启动

要使文件服务器和 Web 界面在启动时自动启动,您可以创建相应的 systemd 服务文件并激活它们。

为 Seafile 文件服务器创建一个 systemd 服务文件:

sudo nano /etc/systemd/system/seafile.service

将以下内容添加到文件中:

创建 /etc/systemd/system/seafile.service

[Unit] Description=Seafile After=network.target mariadb.service [Service] Type=forking ExecStart=/home/sammy/seafile/seafile-server-latest/seafile.sh start ExecStop=/home/sammy/seafile/seafile-server-latest/seafile.sh stop User=sammy Group=sammy [Install] WantedBy=multi-user.target

在这里,ExectStart 和 ExecStop 行表示启动和停止 Seafile 服务的命令。 该服务将以 sammy 作为 User 和 Group 运行。 After 行指定 Seafile 服务将在联网和 MySQL 服务启动后启动。

保存seafile.service并退出。

为 Seahub Web 界面创建一个 systemd 服务文件:

sudo nano /etc/systemd/system/seahub.service

这类似于 Seafile 服务。 唯一的区别是 Web 界面是在 Seafile 服务之后启动的。 将以下内容添加到该文件中:

创建 /etc/systemd/system/seahub.service

[Unit] Description=Seafile hub After=network.target seafile.service [Service] Type=forking ExecStart=/home/sammy/seafile/seafile-server-latest/seahub.sh start ExecStop=/home/sammy/seafile/seafile-server-latest/seahub.sh stop User=sammy Group=sammy [Install] WantedBy=multi-user.target

保存seahub.service并退出。

您可以在 Understanding Systemd Units and Unit Files 教程中了解有关 systemd 单元文件的更多信息。

最后,要使 Seafile 和 Seahub 服务在启动时自动启动,请运行以下命令:

sudo systemctl enable seafile.service sudo systemctl enable seahub.service

当服务器重新启动时,Seafile 将自动启动。

至此,您已经完成了服务器的设置,现在可以测试每个服务。

第 7 步 — 测试文件同步和共享功能

在此步骤中,您将测试您设置的服务器的文件同步和共享功能,并确保它们正常工作。 为此,您需要在单独的计算机和/或移动设备上安装 Seafile 客户端程序。

访问 Seafile 网站上的 下载 页面,然后按照说明在您的计算机上安装最新版本的程序。 Seafile 客户端可用于各种 Linux 发行版(Ubuntu、Debian、Fedora、Centos/RHEL、Arch Linux)、MacOS 和 Windows。 移动客户端适用于 Android 和 iPhone/iPad 设备,可从各自的应用商店下载。

安装 Seafile 客户端后,您可以测试文件同步和共享功能。

在您的计算机或设备上打开 Seafile 客户端程序。 接受 Seafile 文件夹的默认位置,然后单击 Next

在下一个窗口中,输入服务器地址、用户名和密码,然后单击登录

在首页右击【X33X】我的库【X47X】,点击【X63X】同步这个库【X84X】。 接受计算机或设备上位置的默认值。

将文件(例如文档或照片)添加到 My Library 文件夹中。 一段时间后,文件将上传到服务器。 以下屏幕截图显示了复制到 My Library 文件夹的文件 photo.jpg。

现在,登录到 https://your_domain 的 Web 界面并验证您的文件是否存在于服务器上。

单击文件旁边的 共享 以生成此文件的下载链接,您可以共享。

您已验证文件同步工作正常,并且您可以使用 Seafile 从多个设备同步和共享文件和文件夹。

结论

在本教程中,您将设置 Seafile 服务器的私有实例。 现在您可以开始使用服务器来同步文件、添加用户和组,以及在他们之间或与公众共享文件,而无需依赖外部服务。

当有新版本的服务器可用时,请参阅手册的 升级 部分以了解执行升级的步骤。



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3